<?php

namespace App\Http\Controllers\Admin\Superadmin;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class TxController extends Controller
{
	
   public function getIndex()
   {
   		// return 'wqefwefer';
   		$res = DB::table('hs_account')
   			->join('hs_member','hs_member.id','=','hs_account.uid')
   			->where('treat','=',0)
   			->select('hs_account.id','hs_member.id as uid','hs_member.name','hs_account.apply')
   			->get();
   		// dd($res);	
   		return view('admin.superadmin.account.index',['res'=>$res]);
   }

   public function getAgree($acid,$uid,$apply)
   {
   		// return $apply;
   		$id = 5;
   		DB::beginTransaction();
   		$account = DB::table('hs_member')->where('id',$id)->select('account')->first();
   		$new_account = $account->account - $apply;
   		// dd($new_account);

   		//扣除管理员费用
   		$res1 = DB::table('hs_member')->where('id',$id)->update(['account'=>$new_account]);
   		if(!$res1){
   			DB::rollBack();
   			return 'res1失败';
   		}
   		$account = DB::table('hs_member')->where('id',$uid)->select('account')->first();
   		$new_account = $account->account - $apply;

   		//扣除作者余额
   		$res2 = DB::table('hs_member')->where('id',$uid)->update(['account'=>$new_account]);
   		if(!$res2){
   			DB::rollBack();
   			return 'res2失败';
   		}

   		// 事务提交
   		if($res1 && $res2)
   		{
   			DB::commit();
   			$res = DB::table('hs_account')->where('id',$acid)->update(['treat'=>1]);
   			if($res){
   				return back()->with('success','提现成功');

   			}
   		}
   }
		
}		